import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;

/**
 * FilterForm.js
 * @date 2018-12-15

 */
import React from 'react';
import { Button, Col, DatePicker, Form, Input, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import moment from 'moment';
import cacheComponent from 'components/CacheComponent';
import Checkbox from 'components/Checkbox';
import Lov from 'components/Lov';
import { FORM_COL_4_LAYOUT, SEARCH_COL_CLASSNAME, SEARCH_FORM_ITEM_LAYOUT, SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
import intl from 'utils/intl';
import { getDateFormat } from 'utils/utils';
var FilterForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = cacheComponent({
  cacheKey: '/ciam/sub-account-site'
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(FilterForm, _React$Component);

  var _super = _createSuper(FilterForm);

  function FilterForm() {
    var _this;

    _classCallCheck(this, FilterForm);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      advanceForm: false
    };
    return _this;
  }

  _createClass(FilterForm, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var onRef = this.props.onRef;
      onRef(this);
    }
  }, {
    key: "render",
    value: function render() {
      return this.renderAdvanceForm();
    }
  }, {
    key: "renderAdvanceForm",
    value: function renderAdvanceForm() {
      var _this2 = this;

      var _this$props$form = this.props.form,
          getFieldDecorator = _this$props$form.getFieldDecorator,
          getFieldValue = _this$props$form.getFieldValue;
      var _this$state = this.state,
          defaultTenant = _this$state.defaultTenant,
          advanceForm = _this$state.advanceForm;
      var userType = this.props.userType;
      return /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, SEARCH_FORM_ROW_LAYOUT, /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.loginName').d('账号')
      }), getFieldDecorator('loginName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.userType').d('用户类型')
      }), getFieldDecorator('userType', {
        initialValue: 'P'
      })( /*#__PURE__*/React.createElement(Select, {
        onChange: function onChange() {
          setTimeout(function () {
            _this2.handleSearch();
          }, 0);
        }
      }, userType.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.phone').d('手机号码')
      }), getFieldDecorator('phone')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        style: {
          display: advanceForm ? 'inline-block' : 'none'
        },
        onClick: this.toggleForm
      }, intl.get('cpaas.common.button.collected').d('收起查询')), /*#__PURE__*/React.createElement(Button, {
        style: {
          display: advanceForm ? 'none' : 'inline-block'
        },
        onClick: this.toggleForm
      }, intl.get('cpaas.common.button.viewMore').d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({
        style: {
          display: advanceForm ? '' : 'none'
        }
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.email').d('邮箱')
      }), getFieldDecorator('email')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.realName').d('名称')
      }), getFieldDecorator('realName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.tenant').d('所属租户')
      }), getFieldDecorator('organizationId')( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT"
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.user.defaultTenant').d('默认租户')
      }), getFieldDecorator('defaultTenant', {
        initialValue: defaultTenant === undefined ? 0 : 1
      })( /*#__PURE__*/React.createElement(Checkbox, null))))), /*#__PURE__*/React.createElement(Row, Object.assign({
        style: {
          display: advanceForm ? 'block' : 'none'
        }
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cpaas.common.date.active.from').d('有效日期从')
      }), getFieldDecorator('startDateActive')( /*#__PURE__*/React.createElement(DatePicker, {
        style: {
          width: '100%'
        },
        placeholder: "",
        format: getDateFormat(),
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('endDateActive') && moment(getFieldValue('endDateActive')).isBefore(currentDate, 'day');
        }
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cpaas.common.date.active.to').d('有效日期至')
      }), getFieldDecorator('endDateActive')( /*#__PURE__*/React.createElement(DatePicker, {
        style: {
          width: '100%'
        },
        placeholder: "",
        format: getDateFormat(),
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('startDateActive') && moment(getFieldValue('startDateActive')).isAfter(currentDate, 'day');
        }
      }))))));
    }
  }, {
    key: "toggleForm",
    value: function toggleForm() {
      var _this$state$advanceFo = this.state.advanceForm,
          advanceForm = _this$state$advanceFo === void 0 ? false : _this$state$advanceFo;
      this.setState({
        advanceForm: !advanceForm
      });
    }
  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      var form = this.props.form;
      form.resetFields();
    }
  }, {
    key: "handleSearch",
    value: function handleSearch() {
      var onSearch = this.props.onSearch;
      onSearch();
    }
  }]);

  return FilterForm;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype)), _class2)) || _class) || _class);
export { FilterForm as default };